<?php

// 拍卖活动表

namespace app\console\model;

use think\Model;
use think\Request;

class Auction extends Model
{

    // 活动状态获取器
    protected function getStatusTextAttr($value, $data)
    {
        $status = ['1' => '未开始', '2' => '正在进行', '3' => '已结束'];

        return $status[$data['status']];
    }


    // 模型事件
    protected static function init()
    {
        // 新增之前
        self::event('before_insert', function ($data) {
            // 创建时间
            $data->create_time = date('Y-m-d', time());
            $data->status = 1;
        });

        // 写入之前
        self::event('before_write', function ($data) {
            $data->start_time = strtotime(Request::instance()->param('start_time'));
            $data->end_time = strtotime(Request::instance()->param('end_time'));
            $data->picUrl = uploadImg();
        });
    }
}